package com.wsg.lightaccounting.Adapter;

import android.accounts.AccountManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wsg.lightaccounting.Model.AccountBooks;
import com.wsg.lightaccounting.Model.RecordManager;
import com.wsg.lightaccounting.R;

import java.util.List;

/**
 * Created by dell-pc on 2016/11/19.
 */

public class AccountBookListAdapter extends BaseAdapter {
    private Context context;
    private List<AccountBooks> accountBookses;

    public AccountBookListAdapter(Context  context){
        this.context = context;
        accountBookses = RecordManager.accountBookses;
    }
    @Override
    public int getCount() {
        return accountBookses.size();
    }

    @Override
    public Object getItem(int position) {
        return accountBookses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return accountBookses.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       TextView textView;
        if (convertView == null) {
            LayoutInflater inflater =  LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.account_book_layout, null);
            textView = (TextView) convertView.findViewById(R.id.account_book_name);
            convertView.setTag(textView);
        }
        else{
            textView =(TextView) convertView.getTag();
        }

        textView.setText(accountBookses.get(position).getName());
        return convertView;
    }
}
